package io.renren.modules.substation.controller;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.Date;

import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.substation.entity.TInfoParticalConfigEntity;
import io.renren.modules.substation.service.TInfoParticalConfigService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 质点配置表
 *
 * @author yzx
 * @email sunlightcs@gmail.com
 * @date 2020-05-24 09:04:57
 */
@RestController
@RequestMapping("substation/tinfoparticalconfig")
public class TInfoParticalConfigController  extends AbstractController {
    @Autowired
    private TInfoParticalConfigService tInfoParticalConfigService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("substation:tinfoparticalconfig:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tInfoParticalConfigService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{devCode}")
    @RequiresPermissions("substation:tinfoparticalconfig:info")
    public R info(@PathVariable("devCode") String devCode){
		TInfoParticalConfigEntity tInfoParticalConfig = tInfoParticalConfigService.queryByDevCode(devCode);

        return R.ok().put("tInfoParticalConfig", tInfoParticalConfig);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("substation:tinfoparticalconfig:save")
    public R save(@RequestBody TInfoParticalConfigEntity tInfoParticalConfig){


        ValidatorUtils.validateEntity(tInfoParticalConfig, AddGroup.class);

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String date = df.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳


        tInfoParticalConfig.setCreateOpr(getUserId().toString());
        tInfoParticalConfig.setLastOpr(getUserId().toString());
        tInfoParticalConfig.setLastTime(date);
        tInfoParticalConfig.setIsVaild("1");
        tInfoParticalConfig.setCreateTime(date);
		tInfoParticalConfigService.save(tInfoParticalConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("substation:tinfoparticalconfig:update")
    public R update(@RequestBody TInfoParticalConfigEntity tInfoParticalConfig){
		tInfoParticalConfigService.updateById(tInfoParticalConfig);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("substation:tinfoparticalconfig:delete")
    public R delete(@RequestBody String[] devCodes){
		tInfoParticalConfigService.removeByIds(Arrays.asList(devCodes));

        return R.ok();
    }

}
